<!-- 工期风险与影响事件 -->
<template>
  <base-breadcrumb :title="$route.meta.title">
    <a-row
      :gutter="10"
      class="page-height"
    >
      <!-- 树搜索 -->
      <a-col
        :span="6"
        class="permission-collapsed"
        :class="{ 'permission-tree-collapsed': collapsed }"
      >
        <a-card
          :style="{ border: collapsed ? 'none' : 'border: 1px solid #e8e8e8' }"
          class="page-height-tree"
        >
          <title-name title="组织架构" />
          <PermissionTreeOrganization
            :collapsed.sync="collapsed"
            @select="handleSelect"
          />
        </a-card>
      </a-col>
      <a-col
        :span="18"
        class="permission-collapsed page-height-list-wrapper"
        :style="collapsed ? 'width:calc(100% - 10px)' : ''"
      >
        <!-- 搜索 -->
        <searchData
          :search-data="searchOption"
          @search="search"
        />
        <!-- 搜索 -->
        <a-card class="page-height-list">
          <!-- <title-name title="工期风险与影响事件" /> -->
          <div class="table-operator">
            <a-button
              v-btnPermission="[{code:'seex_pm_059_add_02',ident:'prma_seex'},{code:'buco_pm_059_add_02',ident:'prma_buco'}]"
              type="primary"
              @click="handleAdd"
            >新增</a-button>
          </div>
          <div class="pub-table-select-count">
            <a-icon
              type="info-circle"
              theme="twoTone"
            />
            <span style="margin-right: 12px">总数量：<span class="totalNum">{{ totalSize }} 个</span>
            </span>
          </div>
          <list-table
            :defaultLoad="false"
            ref="table"
            size="default"
            rowKey="id"
            :columns="columns"
            :request="loadData"
            :alert="true"
            show-size-changer
            show-quick-jumper
            :page-keys="['pageNum', 'pageSize']"
            show-pagination="auto"
            :loadPage="{
              currentPage: 'pageNum',
              totalSize: 'total',
              data: 'list'
            }"
          >
            <span
              slot="serial"
              slot-scope="text, record, index"
            >{{ index + 1 }}</span>

            <span
              slot="action"
              slot-scope="text, record"
            >
              <a
                v-btnPermission="[{code:'seex_pm_059_loo_01',ident:'prma_seex'},{code:'buco_pm_059_loo_01',ident:'prma_buco'}]"
                @click="handleOperation(record, 'look')"
              >查看</a>
              <template v-if="record.isEditButton">
                <a-divider type="vertical" />
                <a @click="handleOperation(record, 'edit')">编辑</a>
              </template>
            </span>
          </list-table>
        </a-card>
      </a-col>
    </a-row>
  </base-breadcrumb>
</template>

<script>
import { searchOption, columns, mockdata } from './model.js'
import PermissionTreeOrganization from '@/components/businessComponents/PermissionTreeOrganization'
import { getPageProjectRiskEvent } from '@/api/project/limitTimeRisk'
export default {
  name: 'warning',
  components: {
    PermissionTreeOrganization
  },
  data() {
    return {
      totalSize: 0,
      // 收缩展开树
      collapsed: false,
      // 搜索选项
      searchOption,
      //组织架构选中项
      select: null,
      // 查询参数
      queryParam: {},
      columns,
      loadData: async (p) => {
        const obj = {}
        // if (!this.select) {
        //   return
        // }
        // 二级-分公司id
        if (this.select?.tageCode === 'BC') {
          obj.branchId = this.select.orgId
        }
        // 三级-项目id
        if (this.select?.tageCode === 'PD') {
          obj.projectId = this.select.projectId
        }
        let searchData = Object.assign(p, { param: { ...obj, ...this.queryParam } })
        // return { code: 200, data: [], total: 0, pageNum: 0 }
        let res = await getPageProjectRiskEvent(searchData)
        if (res.code == 0) {
          this.totalSize = res.data.total
          return { code: 200, data: res.data.list, ...res.data }
        }
        return { code: 200, data: [], total: 0, pageNum: 0 }
      }
    }
  },

  computed: {},

  watch: {},

  mounted() {},

  methods: {
    /**
     * @description: 树选中
     * @param {object} node 节点对象
     * @return {void}
     */
    handleSelect(node) {
      this.select = node
      this.search()
    },
    // 新增
    handleAdd() {
      this.$router.push({
        path: '/project/limitTimeRisk/edit',
        query: {
          type: 'add'
        }
      })
    },
    /**
     * @description: 操作
     * @param {object} record
     * @param {string} type
     * @return {void}
     */
    handleOperation(record, type) {
      this.$router.push({
        path: '/project/limitTimeRisk/edit',
        query: {
          id: record.id,
          type
        }
      })
    },
    search(val) {
      let params = this.$clone(val)
      this.queryParam = { ...params }
      this.$refs.table.refresh(true)
    }
  }
}
</script>
<style lang='less' scoped>
</style>